//
//  ONDayHeadSectionView.m
//  Volatix
//
//  Created by Nguyen Minh Duc on 6/2/14.
//  Copyright (c) 2014 Familly. All rights reserved.
//

#import "ONDayHeadSectionView.h"
#import "ONScrollViewCell.h"
@interface ONDayHeadSectionView ()

@property NSMutableArray *contents;
@property (nonatomic) CGFloat offsetRadio;
@property (nonatomic) NSInteger activeIndex;
@end



@implementation ONDayHeadSectionView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"ONDayHeadSectionView" owner:self options:nil];
        //[[nib objectAtIndex:0] setFrame:CGRectMake(0, 0, 1024, 352)];
        self = [nib objectAtIndex:0];
        
        [self initICarosel];
        
    }
    return self;
}

-(void) initICarosel
{
     _contents= [[NSMutableArray alloc] init];
    [_contents addObject:@"1"];
    [_contents addObject:@"2"];
    [_contents addObject:@"3"];
    [_contents addObject:@"4"];
    
    // _iCarousel.type = iCarouselTypeLinear;
    [_iCarousel reloadData];
}



#pragma mark -
#pragma mark iCarousel methods

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    
    //NSLog(@"_contents %d",[_contents count]);
    return [_contents count];
}

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
    
    //create new view if no view is available for recycling
    if (view == nil)
    {
        view=[[ONScrollViewCell alloc] initWithFrame:CGRectMake(0, 0, 320.0f, 57.0f)];
        //[view addSubview:scrollViewCell];
    }
    else
    {
        //get a reference to the label in the recycled view
        //label = (UILabel *)[view viewWithTag:1];
    }
    
    return view;
}
- (UIView *)carousel:(iCarousel *)carousel placeholderViewAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
    if (view == nil)
    {
        view=[[ONScrollViewCell alloc] initWithFrame:CGRectMake(0, 0, 320.0f, 57.0f)];
        //[view addSubview:scrollViewCell];
    }
    else
    {
        //get a reference to the label in the recycled view
        //label = (UILabel *)[view viewWithTag:1];
    }
    
    return view;
}
- (CATransform3D)carousel:(iCarousel *)_carousel itemTransformForOffset:(CGFloat)offset baseTransform:(CATransform3D)transform
{
    //implement 'flip3D' style carousel
    transform = CATransform3DRotate(transform, M_PI / 8.0f, 0.0f, 1.0f, 0.0f);
    return CATransform3DTranslate(transform, 0.0f, 0.0f, offset * _iCarousel.itemWidth);
}

- (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
    switch (option)
    {
        case iCarouselOptionWrap:
        {
            return YES;
        }
        case iCarouselOptionSpacing:
        {
            return value ;//1.1f;
        }
        default:
        {
            return value;
        }
    }
}
- (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index
{
    //NSNumber *item = (self.items)[index];
    NSLog(@"Tapped view number: ");
}
-(void)dealloc
{
    _iCarousel.delegate=nil;
    _iCarousel.dataSource=nil;
}
@end
